package com.fulihui.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author: Levon
 * @version: v 0.1 2018-04-28 17:41
 */
public class RegHttpUtil {

    public static String regContent(String content,String args){
        String regEx = "(http:|https:|HTTP:|HTTPS:)\\//[\\d\\w\\.\\/\\-\\?\\=]+";
        Pattern _pattern = Pattern.compile(regEx);
        Matcher _match   = _pattern.matcher(content);
        while (_match.find()){
            StringBuffer buffer = new StringBuffer();
            String aTag = _match.group();
            buffer.append(aTag);
            if(aTag.contains("?")){
                buffer.append("&");
            }else{
                buffer.append("?");
            }
            buffer.append(args);

            StringBuffer replaceBuffer = new StringBuffer();
            replaceBuffer.append(content);
            int index = content.indexOf(aTag+"\">");
            if (index != -1) {
                StringBuffer replaceStr = replaceBuffer.replace(index, index + aTag.length(), buffer.toString());
                content = replaceStr.toString();
            }
        }
        return content;
    }
}
